//
//  XSJMoreHeadView.m
//  XSJ
//
//  Created by yuanyuan he on 2020/4/28.
//  Copyright © 2020 apple. All rights reserved.
//

#import "XSJMoreHeadView.h"
#import "JXLayoutButton.h"

@interface XSJMoreHeadView()

@property (nonatomic, strong) UILabel* nameLabel;
@property (nonatomic, strong) JXLayoutButton* moreButton;

@end

@implementation XSJMoreHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setup];
    }
    return self;
}

- (void)setup
{
    self.backgroundColor = ColorHex(0xffffff);
    [self addSubview:self.nameLabel];
    [self addSubview:self.moreButton];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.equalTo(self);
    }];
    
    [_moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.equalTo(self);
    }];
    self.isShowButton = NO;
}

- (void)moreButtonDidClick:(JXLayoutButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(XSJMoreHeadViewDidClick)]) {
        [self.delegate XSJMoreHeadViewDidClick];
    }
}

-(void)setTitle:(NSString *)title
{
    _title = title;
    _nameLabel.text = _title;
}

-(void)setIsShowButton:(BOOL)isShowButton
{
    _isShowButton = isShowButton;
    
    _moreButton.hidden = !_isShowButton;
}

-(void)setTitleButton:(NSString *)titleButton
{
    _titleButton = titleButton;

    [_moreButton setTitle:_titleButton forState:UIControlStateNormal];
}

- (UILabel *)nameLabel {
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = ColorHex(0x707070);
        _nameLabel.font = [UIFont systemFontOfSize:12];
        _nameLabel.text = @"推荐主播";
    }
    return _nameLabel;
}

- (JXLayoutButton *)moreButton {
    if (_moreButton == nil) {
        _moreButton = [JXLayoutButton buttonWithType:UIButtonTypeCustom];
        [_moreButton setImage:[UIImage imageNamed:@"changgerenshu"] forState:UIControlStateNormal];
        _moreButton.layoutStyle = JXLayoutButtonStyleUpImageDownTitle;//左图右字
        _moreButton.midSpacing = 11.0f;
        [_moreButton setTitle:@"换一换" forState:UIControlStateNormal];
        _moreButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_moreButton setTitleColor:ColorHex(0x696969) forState:UIControlStateNormal];
        [_moreButton addTarget:self action:@selector(wheatButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _moreButton;
}

@end
